//pages/reservation/reservation.js
import http from "../../../utils/http"
let app = getApp()
// import http from '../../../utils/config';
const common = require('../../../public.js')

// const utils = require('../../../utils')
Page({
    data: {
        show: false,//遮罩层
        imageShow: false,//图片
        venueInfo: {},//场馆信息
        storeId: "",	//店铺id
        venueId: "",//场馆id
      
        venuName: '',
        actIndex: 0,
        orderList: ['详情', '须知'],
    },
    // tabs切换
    click_item(e) {
        let index = e.currentTarget.dataset.index
        this.setData({
            actIndex: index
        })
    },
    goBack() {
        const pages = getCurrentPages();
        const prevPage = pages[pages.length - 2]; //上一个页面
        // 从朋友圈进入的时候，页面栈为空，这里需要判断是否有上个页面
        if (prevPage) {
            wx.navigateBack({
                delta: 1
            })
        } else {
            wx.redirectTo({
                url: '/pages/index/index',
            })
        }
    },
    onLoad: function (options) {
        console.log(options);
        let capsule = wx.getMenuButtonBoundingClientRect()
        this.setData({
            height: capsule.height,
            top: capsule.top,
            storeId: options.id,

        })
        this.setData({
            storeId: options.storeId ? options.storeId : 91,
            venueId: options.venueId ? options.venueId : 9,
            venuName: options.name
        })
    },
    onShow: function () {
        this.getDetailInfo()
        // setTimeout(() => {
        //   this.setData({
        //     show: true,
        //     imageShow: true
        //   })
        // }, 10000)
    },
    //点击地图
    mapGuide() {
        if (this.data.venueInfo.ypoint && this.data.venueInfo.xpoint) {
            wx.openLocation({
                latitude: Number(this.data.venueInfo.ypoint),
                longitude: Number(this.data.venueInfo.xpoint),
                name: this.data.venueInfo.storeName ? this.data.venueInfo.storeName : null,
                address: this.data.venueInfo.address ? this.data.venueInfo.address : null,
                scale: 16
            })
        } else {
            common.showToast('未获取到位置信息')
        }
    },
    // 点击预订
    toBook() {
        //   wx.navigateTo({
        //     url: '/packageC/pages/ccc/ccc?venueId=' + this.data.venueId + '&storeId=' + this.data.storeId + '&cityName=' + this.data.venueInfo.cityName + '&storeName=' + this.data.venueInfo.storeName + '&venuName=' + this.data.venuName,
        // })
        wx.navigateTo({
            url: '../choosetime/choosetime?venueId=' + this.data.venueId + '&storeId=' + this.data.storeId + '&cityName=' + this.data.venueInfo.cityName + '&storeName=' + this.data.venueInfo.storeName + '&venuName=' + this.data.venuName,
        })
    },
    //详细信息
    async getDetailInfo() {
        let { storeId, venueId } = this.data
        console.log(this.han, this.id);
        let option = {
            url: "/venue/getStoreVenueDetail",
            data: {
                storeId,
                venueId
            }
        }
        let res = await http(option)
        console.log(res);
        if (res.data.status == 200) {
            // res.data.data.detailImgs = res.data.data.detailImgs.replace('<img ', '<img style="max-width:100%;height:auto;display:block;margin:10px 0;"') 
            var jsonDas = JSON.stringify(res.data.data.detailImgs).replace(/<img/gi, "<img class='richImg'style='max-width:100%;height:auto;display:block;margin:10px 0;'");
            //遍历得到的数据，给img添加CSS和style
            var newResDatas = JSON.parse(jsonDas);
            console.log(newResDatas,"newResDatasnewResDatas")
            var notice = JSON.stringify(res.data.data.notice).replace(/<img/gi, "<img class='richImg'style='max-width:100%;height:auto;display:block;margin:10px 0;'");
            //遍历得到的数据，给img添加CSS和style
            var notice = JSON.parse(notice);
            console.log(notice)
            this.setData({
                venueInfo: res.data.data,
                detailImgs: newResDatas,
                notice: notice
            })
        }
    },
    //点击遮罩层
    onClickHide() {
        this.setData({
            show: false,
            imageShow: false
        });
    },
    onShareAppMessage() {

    },
    onShareTimeline() {

    },
    onClose() {
        this.setData({ showShare: false });
    },
    // 导航栏左侧小图标
    clickLeft() {
        wx.navigateBack({
            delta: 1,
        })
    },
    // 点击客服
    handleContact(e) {
        console.log(e.detail.path)
        console.log(e.detail.query)
    },
    // 点击电话
    clickPhone() {
        wx.makePhoneCall({
            phoneNumber: this.data.venueInfo.mobile //仅为示例，并非真实的电话号码
        })
    },

})